from PyQt5.Qt import *  # 刚开始学习可以这样一下导入
import sys


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QGridLayout的学习")
        self.resize(400, 400)
        self.set_ui()

    def set_ui(self):
        gridLayout = QGridLayout()

        label1 = QLabel("标签1")
        label1.setStyleSheet("background-color:red;")
        label2 = QLabel("标签2")
        label2.setStyleSheet("background-color:green;")
        label3 = QLabel("标签3")
        label3.setStyleSheet("background-color:yellow;")

        # 添加控件
        gridLayout.addWidget(label1, 0, 0)
        gridLayout.addWidget(label2, 1, 0, 2, 2)

        # gridLayout.addWidget(label2,0,1)
        # gridLayout.addWidget(label3,1,0)
        # 合并单元格的时候要告诉它 跨越多少行 和跨越多少列
        # gridLayout.addWidget(label3,1,0,1,2)   #从1 0开始 它占的是1行 2 列
        # gridLayout.addWidget(label3,1,0,3,3)   #从1 0开始 它占的是3行 3 列

        # 添加布局
        # gridLayout.addLayout()   #它的智能提示不是太好

        # 获取
        # print(gridLayout.getItemPosition(2))
        # print(gridLayout.itemAtPosition(1,1).widget().text())

        self.setLayout(gridLayout)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
